import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import interp1d

# 读取你的数据（CSV / Excel 都可以）
df = pd.read_csv("linlin.csv")

# WHO 男婴标准体重（0~90天）
who_age = np.array([0, 30, 60, 90])
who_standards = {
    "-3SD": [2.0, 3.2, 4.1, 4.9],
    "-2SD": [2.5, 3.8, 4.8, 5.6],
    "-1SD": [2.9, 4.3, 5.5, 6.3],
    "Median": [3.3, 4.9, 6.1, 7.0],
    "+1SD": [3.9, 5.6, 6.9, 7.8],
    "+2SD": [4.4, 6.3, 7.6, 8.6],
    "+3SD": [5.0, 7.1, 8.4, 9.4]
}

# 插值生成完整 0~90 天的标准曲线
days = np.arange(0, 91)
interp_curves = {
    key: interp1d(who_age, vals)(days) for key, vals in who_standards.items()
}

# 绘图
plt.figure(figsize=(10, 5))
for key, vals in interp_curves.items():
    plt.plot(days, vals, '--', label=key)

# 加入宝宝实际数据
plt.plot(df["AgeDays"], df["Weight"], 'o-', color='black', label="Actual Weight")

plt.title("Weight-for-Age Growth Chart (vs WHO)")
plt.xlabel("Age (days)")
plt.ylabel("Weight (kg)")
plt.grid(True)
plt.legend()
plt.tight_layout()
plt.savefig("growth_curve.png")  # 保存为图片
plt.show()
